<template>
  <h1>员工列表综合练习</h1>
  <el-form style="width: 424px;margin: 0 auto" label-width="100px">
    <el-form-item label="姓名">
      <el-input placeholder="请输入姓名" type="text" v-model="user.name"/>
    </el-form-item>
    <el-form-item label="工资">
      <el-input placeholder="请输入工资" type="text" v-model="user.salary"/>
    </el-form-item>
    <el-form-item label="岗位">
      <el-input placeholder="请输入岗位" type="text" v-model="user.job"/>
    </el-form-item>
    <el-form-item>
      <el-button type="success" @click="submit" >点我提交</el-button>
    </el-form-item>
  </el-form>
  <el-table :data="list" border style="width: 600px;margin: 0 auto">
    <el-table-column type="index" label="编号" width="83" align="center"></el-table-column>
    <el-table-column prop="name" label="姓名" align="center"></el-table-column>
    <el-table-column prop="salary" label="工资" width="83" align="center"></el-table-column>
    <el-table-column prop="job" label="岗位" align="center"></el-table-column>
    <el-table-column label="操作" align="center">
      <template #default="scope">
        <el-button type="danger" @click="dele(scope)" style="margin-left: 30px" >删除</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>
<script setup>
import {ref} from "vue";

const user = ref({name: '', salary: '', job: ''});
const list = ref([]);
//删除按钮
const dele = (obj) => {
  console.log(obj);
  console.log(obj.$index);
  if (confirm("你确定要删除" + obj.row.name + "吗？")) {
    list.value.splice(obj.$index, 1);
  }
};
//提交按钮
const submit = () => {
  if (user.value.name === '' || user.value.salary === '' || user.value.job === '') {
    alert("请填写完整信息");
  } else {
    list.value.push({...user.value});
    user.value.name = '';
    user.value.salary = '';
    user.value.job = '';
  }
}
</script>
<style scoped>

</style>